class P10115 {

	public static void main(String[] args) {
		String line = readLn();
		while (!"0".equals(line)) {
			process(Integer.parseInt(line));
			line = readLn();
		}
	}

	private static void process(int i) {
		String[][] rules = new String[i][2];
		for (int k = 0; k < i; k++) {
			rules[k][0] = readLn();
			rules[k][1] = readLn();
		}
		
		String line = readLn();
		
		for (int k = 0; k < i; k++) {
			int initIndex = line.indexOf(rules[k][0]);
			while (initIndex > -1) {
//				System.out.println("Find: " + rules[k][0]);
				line = replace(initIndex, rules[k][0],  rules[k][1], line);
				initIndex = line.indexOf(rules[k][0]);
			}
		}
		
		System.out.println(line);
	}

	private static String replace(int initIndex, String find, String rule, String line) {
		int endIndex = find.length() + initIndex;
		
		
		
		String firstPart = line.substring(0, initIndex);
		
		String finalPart = line.substring(endIndex);
		
//		System.out.println("Replace: " + rule);
//		
//		System.out.println("Line: " + line);
//		
//		
//		System.out.println("first: " + firstPart);
//		System.out.println("Final: " + finalPart);
//		
//		System.out.println("New: " + firstPart + rule + finalPart);
//		System.out.println("--------");
		return firstPart + rule + finalPart;
	}

	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString());
	}

}
